﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Autenticar.Authenticate += new AuthenticateEventHandler(Login1_Authenticate);
       
    }


    public void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        
        DTO.DTOUsuario DtoUsuario = new DTO.DTOUsuario();
        DtoUsuario.Login = Autenticar.UserName.ToLower();
        DtoUsuario.Senha = Autenticar.Password;
        BO.BOUsuario BoUsuario = new BO.BOUsuario();
        BoUsuario.Consultar(DtoUsuario);
        
        
        if (BoUsuario.Consultar(DtoUsuario))
        {
            Session.Add("login", DtoUsuario.Login); // criar variavel de sessão login
            this.Response.Redirect("Home.aspx");
        }
        else
        {
            Autenticar.FailureText = "Usuário e/ou senha inválidos!";
        }

    }   

}
